<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="app">
    <my-com></my-com>
  </div>
  <script>
    let com = {
      data() {
        return {}
      },
      methods: {

      },
      template: `
        <div>
          我是组件  
        </div>
      `
    }
    // 声明一个混入对象
    let mixin = {
      data() {
        return {
          msg: 'this is mixin data',
          obj: {
            name: 'wangwu',
            gender: 'male'
          }
        }
      },
      methods: {
        myFun() {
          console.log('this is mixin funtion');
        }
      },
      created() {
        console.log('this is mixin created');
      }
    }
    // 全局混入
    Vue.mixin(mixin)
    let vm = new Vue({
      el: "#app",
      data: {
        name: '张三',
        obj: {
          name: 'lisi',
          age: 12
        }
      },
      methods: {
        myFun() {
          console.log('this is vue funtion');
          return 'Nihao'
        }
      },
      created() {
        console.log('this is vue created');
      },
      // 混入对象的局部注册
      // mixins: [mixin]
      components: {
        myCom: com
      }
    })
  </script>
</body>

</html>